<script type="text/html" template lay-done="layui.data.done(d.params)">
  <div class="layui-form" lay-filter="form_online">
    {{# var data = d.params || {} }}
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">奖品名称</label>
        <div class="layui-input-inline">
          <input id="award_name" name="name" type="text" lay-verify="required" class="layui-input"
                 value="{{data.name || ''}}"/>
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label">奖品等级</label>
        <div class="layui-input-inline" style="width: 100px">
          <select name="level" lay-verify="required">
            <option>1</option>
            <option>2</option>
            <option>3</option>
            <option>4</option>
            <option>5</option>
          </select>
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label form-required">奖品数量</label>
        <div class="layui-input-inline">
          <input type="number" class="layui-input" name="amount"
                 autocomplete="off" value="{{data.amount || ''}}" lay-verify="required">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label form-required">中奖概率</label>
        <div class="layui-input-inline" style="width: 100px">
          <input type="text" class="layui-input" name="rate" placeholder="请输入中奖概率"
                 autocomplete="off" value="{{data.rate || ''}}" lay-verify="required">
        </div>
        <div class="layui-input-inline layui-word-aux layui-form-mid">
          %
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label"></label>
      <div class="layui-inline">
        每人最多可中奖
      </div>
      <div class="layui-inline" style="width: 80px">
        <input type="number" class="layui-input" name="user_limit" placeholder=""
               autocomplete="off" value="{{data.user_limit || 0}}" lay-verify="required">
      </div>
      <div class="layui-inline">
        次
      </div>
      <div class="layui-inline layui-word-aux">
        （值为0时表示不限制）
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label form-required" id="logo_label">奖品图片</label>
      <div class="layui-input-inline">
        <div id="logo_url"></div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label form-required">奖品说明</label>
      <div class="layui-input-block" style="width: 600px">
        <div id="award_desc">{{ data.description || '' }}</div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label"></label>
      <div class="layui-input-inline">
        <input type="hidden" name="id" value="{{data.id || ''}}"/>
        <a class="layui-btn" lay-submit lay-filter="submit_award">保存</a>
      </div>
    </div>
  </div>
</script>
<script>
  layui.data.done = function (obj) {
    layui.use(['fox_upload', 'wangEditor'], function () {
      let $ = layui.$
        , form = layui.form
        , admin = layui.admin
        , fox_upload = layui.fox_upload
        , editor = layui.wangEditor

      $('select[name="level"]').val(obj.level)
      form.render()

      //编辑器
      editor.render({
        elem: "#award_desc"
        , height: 300
        , name: 'description'
        , url: 'editor/images'
      });

      //上传控件初始化
      fox_upload.render({
        elem: '#logo_url'
        , url: 'agent-admin/lotteries/award_image'
        , headers: {
          Authorization: admin.getAccessToken('Bearer')
        }
        , text: '点击上传'
        , name: 'logo_url'
        , value: obj.logo_url || ''
      })
    })
  }
</script>

